package com.deke.home.controller;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.deke.entity.AclUser;
import com.deke.entity.TbZone;
import com.deke.home.service.TbZoneService;
import com.deke.home.vo.TbZoneVo;
import com.deke.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author ：ludi（206913808@qq.com）
 * @date ：Created in 2022/12/5 19:24
 * @description：
 * @modified By：
 * @version:
 */
@Api(tags = "专区管理")
@RestController
@RequestMapping("/home/zone")
public class TbZoneController {


    @Autowired
    private TbZoneService tbZoneService;


    @ApiOperation(value = "分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current",value = "当前页码"),
            @ApiImplicitParam(name = "pageSize",value = "每页显示的条数")
    })
    @PostMapping("getAllZone/{current}/{pageSize}")
    public Result<IPage<TbZone>> getAllZone(@PathVariable(required = true) Integer current, @PathVariable(required = true) Integer pageSize, @RequestBody TbZoneVo tbZoneVo) {
        return tbZoneService.queryByConditionPage(current, pageSize, tbZoneVo);
    }



    @ApiOperation(value = "删除操作")
    @PostMapping("deleteZone")
    public Result deleteZone(TbZone tbZone , @RequestBody Map map ) {
        tbZone.setIsDeleted("1");
        tbZoneService.deleteZone(tbZone,map.get("id").toString());
        return new Result(2000, "删除成功");
    }



    @ApiOperation(value = "添加操作")
    @PostMapping("addZone")
    public Result addZone(@RequestBody TbZone tbZone) {
        if (StrUtil.isNotEmpty(tbZone.getId())){
            tbZoneService.updateZone(tbZone);
            return new Result(2000, "修改成功");
        }else {
            tbZoneService.addZone(tbZone);
            return new Result(2000, "添加成功");
        }

    }



    @ApiOperation(value = "改变状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "id"),
            @ApiImplicitParam(name = "isDisable",value = "状态(0或1)")
    })
    @PostMapping("changeStatus/{id}/{isDisable}")
    public Result changeStatus(TbZone tbZone, @PathVariable String id, @PathVariable Integer isDisable) {
        tbZoneService.changeStatus(tbZone, isDisable);
        return new Result(2000, "状态改变成功");
    }


}